package service

import (
	"seat-service/initialization"
	"seat-service/model"
	"seat-service/model/dto"
)

type ClassroomService struct {
}

func (c *ClassroomService) GetByBuildingAndName(par dto.ClassroomLike) (classrooms []model.Classroom, err error) {
	err = initialization.DB.Where("building_id = ? and location like ?", par.BuildingId, "%"+par.Name+"%").Find(&classrooms).Error
	return
}

func (*ClassroomService) GetById(id uint) (classrooms model.Classroom, err error) {
	err = initialization.DB.Where("id = ?", id).Find(&classrooms).Error
	return
}

func (*ClassroomService) GetByBuildingID(bID uint) (classrooms []model.Classroom, err error) {
	err = initialization.DB.Where("building_id = ?", bID).Find(&classrooms).Error
	return
}

func (*ClassroomService) GetByBuildingIDAndPage(bID uint, page dto.PageParam) (classrooms []model.Classroom, err error) {
	err = initialization.DB.Where("building_id = ?", bID).Offset((page.PageNo - 1) * page.PageSize).Limit(page.PageSize).Find(&classrooms).Error
	return
}

func (*ClassroomService) GetAll() (classrooms []model.Classroom, err error) {
	err = initialization.DB.Find(&classrooms).Error
	return
}

func (*ClassroomService) GetReserveByClassroomStatue(statue int) (classrooms []model.Classroom, err error) {
	err = initialization.DB.Where("classroom_status = ?", statue).Find(&classrooms).Error
	return
}
